package com.yzpc.mapper;
import com.yzpc.entity.MouseClick;
import com.yzpc.entity.Script;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface MouseClickMapper {
    int insertMouseClick(MouseClick mouseClick);

    @Select("SELECT * FROM mouse_clicks WHERE script_id IS NULL")
    List<MouseClick> getMouseClicksWithoutScriptId();

    @Update("UPDATE mouse_clicks SET script_id = #{scriptId} WHERE script_id IS NULL")
    void updateMouseClickScriptId(@Param("scriptId") Integer scriptId);

    @Select("SELECT * FROM mouse_clicks WHERE script_id = #{scriptId}")
    List<MouseClick> findMouseClicksByScriptId(int scriptId);

    @Select("SELECT * FROM scripts WHERE used = 1 LIMIT 1")
    Script findUsedScript();

    @Update("UPDATE scripts SET used = 0 WHERE script_id = #{scriptId}")
    int setScriptUsedToZero(int scriptId);
}
